// 获取参数
window.shareOpenAppUrl = function (url) {// 参数为当前页面地址
    var openappurl = "";
    if (url.indexOf("video") >= 0 && url.indexOf("live") >= 0) {// 直播
        openappurl = "yfapp://redirectPage/?page=liveDetail&params=";
    } else if (url.indexOf("channelvertical") >= 0 && url.indexOf("play") >= 0) {// 秀场直播
        openappurl = "yfapp://redirectPage/?page=liveShow&params=";
    } else if (url.indexOf("video") >= 0 && url.indexOf("voddetail") >= 0) {// 视频
        openappurl = "yfapp://redirectPage/?page=video&params=";
    } else if (url.indexOf("albumList") >= 0) {// 专辑
        openappurl = "yfapp://redirectPage/?page=albumDetail&params=";
    } else if (url.indexOf("special") >= 0) {// 专题
        openappurl = "yfapp://redirectPage/?page=subjectDetail&params=";
    } else if (url.indexOf("showhomepage") >= 0 || url.indexOf("homepage") >= 0) {// 频道首页
        openappurl = "yfapp://redirectPage/?page=channelMain&params=";
    } else {
        openappurl = "yfapp://redirectPage/?page=newsDetail&params=";
    }
    return openappurl;
};

// 加入params参数值
var appurl = shareOpenAppUrl($location.absUrl());
// $stateParams为当前页面参数对象，从该对象中去相应的参数值
if (appurl.indexOf("liveDetail") >= 0 || appurl.indexOf("liveShow") >= 0) {
    var paramobj = {programid: $stateParams.programid}// 节目id
    appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
} else if (appurl.indexOf("video") >= 0) {
    var paramobj = {videoid: $stateParams.videoid}// 视频id
    appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
} else if (appurl.indexOf("albumDetail") >= 0) {
    var paramobj = {// 专辑，isshare=1代表是分享页，此处替换为在APP中打开专辑页
        albumDetailUrl: $location.absUrl().replace("isshare=1", "isPhoneFromYF=1")
    }
    appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
} else if (appurl.indexOf("subjectDetail") >= 0) {
    var paramobj = {subjectId: $stateParams.specialid}// 专题id
    appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
} else if (appurl.indexOf("channelMain") >= 0) {
    var paramobj = {channelid: $stateParams.channelid}// 频道id
    appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
} else {
    // $location.absUrl()为当前页面地址
    appurl = appurl + encodeURIComponent($location.absUrl());
}

// 打开地址
window.openDownPage = function (appurl) {
    var tempurl = base64Encode(appurl);
    //tempurl中+，=等着3个符号是特殊符号会导致获取参数失败，所以此处做了一个替换
    tempurl = tempurl.replace(/\//g, "_a").replace(/\+/g, "_b").replace(/\=/g, "_c");
    //host: //现网 //share.96189.com", //测试网 //testkfw.butel.com:81
    var temphref = window.yfH5ShareApp.host + "/plug/yfapp.html?appurl=" + tempurl;
    location.href = temphref;
};
